package com.zzq.service.impl;

import com.zzq.entity.Fruit;
import com.zzq.mapper.FruitMapper;
import com.zzq.service.FruitService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzq.util.DataUtil;
import com.zzq.vo.Barvo;
import com.zzq.vo.Datavo;
import com.zzq.vo.Pievo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzq
 * @since 2021-08-22
 */
@Service
public class FruitServiceImpl extends ServiceImpl<FruitMapper, Fruit> implements FruitService {

    @Autowired
    private FruitMapper fruitMapper;

    @Override
    public Barvo barvoList() {

        Barvo barvo = new Barvo();
        List<String> names = new ArrayList<>();
        List<Datavo> values = new ArrayList<>();

        //先查出数据库的数据
        List<Fruit> fruits = this.fruitMapper.selectList(null);
        //遍历每一个水果对象
        for (Fruit fruit : fruits) {
            //把水果的名字放在names里面
            names.add(fruit.getName());

            //把水果的销量和颜色放到values里面
            Datavo datavo = new Datavo();

            datavo.setValue(fruit.getSale());
            datavo.setItemStyle(DataUtil.createItemStyle(fruit.getSale()));

            values.add(datavo);

        }
        //再转换成写好的 vo 类型
        barvo.setNames(names);
        barvo.setValues(values);

        return barvo;
    }

    @Override
    public List<Pievo> pievoList() {
        List<Pievo> pievoList = new ArrayList<>();

        //先查出数据库的数据
        List<Fruit> fruits = this.fruitMapper.selectList(null);
        for (Fruit fruit : fruits) {
            Pievo pievo = new Pievo();
            pievo.setValue(fruit.getSale());
            pievo.setName(fruit.getName());

            pievoList.add(pievo);
        }
        return pievoList;
    }


}
